package com.github.gaojh.example.aop;

import cn.hutool.aop.ProxyUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.gaojh.aop.AopExecution;
import com.github.gaojh.example.service.DemoService;
import com.github.gaojh.example.service.DemoService1;
import com.github.gaojh.mvc.annotation.POST;
import com.github.gaojh.server.utils.JsonTools;
import com.github.gaojh.server.utils.PathMatcher;

import java.sql.Struct;

/**
 * @author gaojh
 * @since 2020/3/26
 */
public class Test {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        /*DemoA a = new DemoA();
        DemoAop aop = new DemoAop();

        DemoA b = ProxyUtil.proxy(a,aop);
        System.out.println("---"+b.t());*/

        //com.gao..*.Con*
        //com\.gao\.(\w|\.)*\.Contr\w*

      //  String p = "com\\.gao\\.(\\w|\\.)*\\.Contr\\w*";
       // System.out.println(ReUtil.isMatch(p, "com.gao.flying.Controller"));
        //System.out.println(PathMatcher.path.match(p, "com.gao.demo.flying.Controll"));

//        AopExecution aopExecution =new AopExecution();
//        aopExecution.setExecution("* com.spring.*.Business*.*()");
//
//        System.out.println(JsonTools.DEFAULT.toJson(aopExecution));
//        String basePackage = "com.gao..service.*";
//        basePackage = StrUtil.replace(basePackage, "..*", "\\%([a-zA-Z]|%)#\\%");
//        basePackage = StrUtil.replace(basePackage, "..", "\\%([a-zA-Z]|%)#\\%");
//        basePackage = StrUtil.replace(basePackage, ".*.", "\\%([a-zA-Z])#\\%");
//        basePackage = StrUtil.replace(basePackage, ".*", "\\%([a-zA-Z])#");
//        basePackage = StrUtil.replace(basePackage, "*.", "([a-zA-Z])#\\%");
//        basePackage = StrUtil.replace(basePackage,"#","*");
//        basePackage = StrUtil.replace(basePackage,".","\\.");
//        basePackage = StrUtil.replace(basePackage,"%",".");
//
//        System.out.println(basePackage);

   //     System.out.println(ReflectUtil.getConstructors(DemoService1.class));

        DemoA demoA = ProxyUtil.proxy(DemoA.class.newInstance(),DemoAdapter.class);
        System.out.println(demoA);
        DemoB demoB = ProxyUtil.proxy(DemoB.class.newInstance(),DemoAdapter.class);
        System.out.println(demoB);
        ReflectUtil.setFieldValue(demoB,ReflectUtil.getField(demoB.getClass(),"demoA"),demoA);

        demoB.run();
    }
}
